package pong.mathematic;

public class Vector3D extends Vector {
	private float x, y, z;

	public Vector3D() {
		x = 0;
		y = 0;
		z = 0;
	}

	public Vector3D(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public Vector3D(Vector2D vec, float z) {
		if (vec == null) {
			x = 0;
			y = 0;
		} else {
			x = vec.getX();
			y = vec.getY();
		}
		this.z = z;
	}

	public Vector3D(Vector3D vec) {
		if (vec == null) {
			x = 0;
			y = 0;
			z = 0;
		} else {
			x = vec.x;
			y = vec.y;
			z = vec.z;
		}
	}

	@Override
	public void add(Vector vec) {
		if (vec instanceof Vector3D) {
			add(((Vector3D) vec).getX(), ((Vector3D) vec).getY(), ((Vector3D) vec).getZ());
		} else {
			add(((Vector2D) vec).getX(), ((Vector2D) vec).getY(), 0);
		}
	}

	public void add(float x, float y, float z) {
		this.x += x;
		this.y += y;
		this.z += z;
	}

	@Override
	public void add(float decimal) {
		x += decimal;
		y += decimal;
		z += decimal;
	}

	@Override
	public void minus(Vector vec) {
		if (vec instanceof Vector3D) {
			minus(((Vector3D) vec).getX(), ((Vector3D) vec).getY(), ((Vector3D) vec).getZ());
		} else {
			minus(((Vector2D) vec).getX(), ((Vector2D) vec).getY(), 0);
		}
	}

	public void minus(float x, float y, float z) {
		this.x -= x;
		this.y -= y;
		this.z -= z;
	}

	@Override
	public void minus(float decimal) {
		x -= decimal;
		y -= decimal;
		z -= decimal;
	}

	@Override
	public void multy(float decimal) {
		x *= decimal;
		y *= decimal;
		z *= decimal;
	}

	@Override
	public void divide(float decimal) {
		x /= decimal;
		y /= decimal;
		z /= decimal;
	}

	@Override
	public float distance() {
		return (float) Math.sqrt(x * x + y * y + z * z);
	}

	@Override
	public float distance(Vector vec) {
		if (vec instanceof Vector3D) {
			return (float) Math.sqrt(D(x, ((Vector3D) vec).getX()) + D(y, ((Vector3D) vec).getY())
					+ D(z, ((Vector3D) vec).getZ()));
		} else {
			return (float) Math.sqrt(D(x, ((Vector2D) vec).getX()) + D(y, ((Vector2D) vec).getY()));
		}
	}

	@Override
	public void normalize() {
		float length = distance();
		if(length == 0) {
			x = 0;
			y = 0;
			z = 0;
		}
		else {
			x /= length;
			y /= length;
			z /= length;
		}
	}

	@Override
	public void setVector(Vector vec) {
		x = ((Vector3D) vec).getX();
		y = ((Vector3D) vec).getY();
		if (vec instanceof Vector3D) {
			z = ((Vector3D) vec).getZ();
		}

	}

	@Override
	public String toString() {
		String result = "x=" + x + ", y=" + y + ", z=" + z;
		return result;
	}

	@Override
	public boolean equals(Object vec) {
		if (vec instanceof Vector3D) {
			return ((Vector3D) vec).getX() == getX() && ((Vector3D) vec).getY() == getY()
					&& ((Vector3D) vec).getZ() == getZ();
		} else {
			return false;
		}
	}

	@Override
	public double angle() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void rotateCoordinates(double tiltAngle) {
		// TODO Auto-generated method stub

	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	public float getZ() {
		return z;
	}

	public void setX(float x) {
		this.x = x;
	}

	public void setY(float y) {
		this.y = y;
	}

	public void setZ(float z) {
		this.z = z;
	}

	public void setXYZ(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
}
